package com.yiyang.controller;


import com.yiyang.pojo.Building;
import com.yiyang.pojo.vo.PageResult;
import com.yiyang.pojo.vo.Result;
import com.yiyang.service.BuildingService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/building")
@Tag(name = "BuildingController",description = "楼宇信息")
public class BuildingController {
    @Autowired
    private BuildingService buildingService;
    @GetMapping("/{id}")
    public Result<Building> getBuildingById(@PathVariable("id") Integer id){
        return buildingService.getBuildingById(id);
    }
    @GetMapping
    public Result<PageResult<List<Building>>> getAllBuilding(
            @RequestParam(name = "currentPage",defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize,
            @RequestParam(name = "name",defaultValue = "") String name
    ){
        return buildingService.getAllBuilding(currentPage,pageSize,name);
    }

    @PutMapping
    public Result<Void> addBuilding(@RequestBody Building building){
        return buildingService.addBuilding(building);
    }

    @PostMapping
    public Result<Void> updateBuilding(@RequestBody Building building){
        return buildingService.updateBuilding(building);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteBuilding(@PathVariable("id") Integer id){
        return buildingService.deleteBuilding(id);
    }
}
